package org.czl;

public class csdn_24 {
    //设计一个结点类, 因为会设计到环形链表所以自己设计是最好的
    private static class Node{
        int value;
        Node next;
        public Node(int value){
            this.value = value;
        }
    }
    // m 个人 m 个人会噶
    public int circle(int n, int m) {
        Node head = new Node(0);
        Node temp = head;
        for(int i = 1 ; i < n ; i++){
            temp.next = new Node(i);
            temp = temp.next;
        }
        temp.next = head;
        int index = 0;
        while(head.next != head){
            if(index == m-2){
                head.next = head.next.next;
                index = 0;
            }
            else{
                index++;
            }
            head = head.next;
        }
        return head.value;
    }
}
